<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .father {
        width: 300px;
        height: 300px;
        background-color: #f00;
      }

      .son {
        width: 100px;
        height: 100px;
        background: #0f0;
      }
    </style>
  </head>
  <body>
    <div id="app">

      <!-- 这个father的点击事件，只能由自身触发，不能由冒泡 -->
      <div class="father" @click.self="fatherClick">

        <!-- 阻止冒泡 -->
        <div class="son" @click.stop="fn1"></div>

        <!-- 只绑定一次 -->
        <button @click.once="fn2">点我啊</button>

        <!-- 阻止默认行为 -->
        <a @click.prevent="fn3" href="http://www.itcast.cn">点我</a>

        <!-- 既想阻止默认行为，又想阻止冒泡 -->
        <a @click.stop.prevent="fn3" href="http://www.itcast.cn">点我</a>

      </div>
    </div>
    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: '#app',
        data () {
          return {}
        },
        methods: {
          fatherClick () {
            alert('father被点了')
          },
          fn1 () {
            alert('son被点了')
          },
          fn2 () {
            alert('按钮被点了')
          },
          fn3 () {
            alert('a被点了')
          }
        }
      })
    </script>
  </body>
</html>
